#pragma once
#include"public_struct.h"
vector<vector<int>> generateMatrix(int n) {
	vector<vector<int>> result(n, vector<int>(n));
	int i = 0, j = 0, k = 1;
	int flag = 1;
	while (k <= n * n) {
		result[i][j] = k++;
		if (flag == 1) {
			if (j == n - 1 || result[i][j + 1]) {
				flag = 2;
				i++;
			}
			else {
				j++;
			}
		}
		else if (flag == 2) {
			if (i == n - 1 || result[i + 1][j]) {
				flag = 3;
				j--;
			}
			else {
				i++;
			}
		}
		else if (flag == 3) {
			if (j == 0 || result[i][j - 1]) {
				flag = 4;
				i--;
			}
			else {
				j--;
			}
		}
		else {
			if (i == 0 || result[i - 1][j]) {
				flag = 1;
				j++;
			}
			else {
				i--;
			}
		}
	}
	return result;
}

